package com.useeinfo.oa.common.utils.exception;

import com.useeinfo.oa.common.exception.MyException;
import com.useeinfo.oa.common.exception.dto.ExceptionDto;
import com.useeinfo.oa.common.utils.exception.view.AccessDeniedJudgmentView;
import com.useeinfo.oa.common.utils.exception.view.DefaultJudgmentView;
import com.useeinfo.oa.common.utils.exception.view.MyExceptionJudgmentView;
import com.useeinfo.oa.common.utils.exception.view.RuntimeJudgmentView;
import org.springframework.security.access.AccessDeniedException;

/**
 * @author geniusj
 * @email 975473185@qq.com
 * @date 2018/8/20  下午3:16
 */
public class DefaultJudgmentViewFactory implements JudgmentViewFactory{

    private JudgmentView judgmentView;

    @Override
    public ExceptionDto getViewDetailFactory(Exception ex) {
        if(ex instanceof MyException){
            judgmentView = new MyExceptionJudgmentView((MyException)ex);
        }else if(ex instanceof AccessDeniedException){
            judgmentView = new AccessDeniedJudgmentView((AccessDeniedException) ex);
        }else if(ex instanceof RuntimeException){
            judgmentView = new RuntimeJudgmentView((RuntimeException) ex);
        }else {
            judgmentView = new DefaultJudgmentView(ex);
        }
        return judgmentView.getViewDetail();
    }
}
